package com.liuwei.spring.cloud.framework.db.mapper;/**
 * @author : BaseMapper
 * @version V1.0
 * @date: 2023/5/10 5:56 下午
 * @Description: TODO
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liuwei.spring.cloud.framework.db.entity.BaseOptimisticLockerEntity;

/**
 * @author : BaseMapper
 * @version V1.0
 * @date: 2023/5/10 5:56 下午
 * @Description: TODO
 */
public interface BaseOptimisticLockerMapper<T extends BaseOptimisticLockerEntity> extends BaseMapper<T> {

    /**
     * 乐观锁支持 update 批量更新
     * @param entity 更新值
     * @param updateWrapper 查询条件
     * @return 影响行数
     *
     * updateById 支持乐观锁需先取出当前 version;  set version = newVersion where version = oldVersion;
     * 对于 new entity() 则更新失败
     */
    /*@Override
    default int update(T entity, Wrapper<T> updateWrapper){
        List<T> records = selectList(updateWrapper);
        if(CollectionUtils.isEmpty(records)){
            return 0;
        }
        CollectionUtils.emptyIfNull(records).forEach(x->{
            String id = x.getId();
            x.setId(id);
            Validators.isTrue(updateById(x)>0, StrUtil.format("Id:{} 乐观锁并发,更新失败"));
        });
        return CollectionUtils.emptyIfNull(records).size();
    }*/
}
